{include file="public/header" /}
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>{$Think.lang.fuwu_personal}</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>

        <form id="form" method="post" name="form1">

            <input type="hidden" name="id" value="{$data.id}" id="id"/>
            <input type="hidden" name="admin_id" value="{$data.admin_id}" id="admin_id"/>
            <table class="ds-default-table">
                <tbody>
                <tr class="noborder">
                    <td class="required w120">{$Think.lang.fuwu_personal_code1}:</td>
                    <td class="vatop rowform"><input type="text" value="{$data.prevcode}" name="prevcode" id="prevcode" class="txt"></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120"><label class="validation">{$Think.lang.fuwu_personal_skillid}:</label></td>
                    <td class="vatop rowform">
                        <select name="skillid" id="skillid">
                            <option value="">--请选择</option>
                            {foreach name='skillArr' item='v'}
                            <option value="{$v.id}" {if $data.skillid== $v.id} selected {/if}>{$v.name}</option>
                            {/foreach}
                        </select>
                    </td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120"><label class="validation">{$Think.lang.fuwu_personal_phone}:</label></td>
                    <td class="vatop rowform"><input type="text" value="" name="phone" id="phone" class="txt"></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120"><label class="validation">{$Think.lang.fuwu_personal_password}:</label></td>
                    <td class="vatop rowform"><input type="password" value="{$data.password}" name="password" id="password" class="txt"></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120"><label class="validation">{$Think.lang.fuwu_personal_password_queren}:</label></td>
                    <td class="vatop rowform"><input type="password" value="{$data.password}" name="quren_password" id="quren_password" class="txt"></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120">{$Think.lang.fuwu_personal_avtar}:</td>
                    <td class="vatop rowform" id="upload_img_avtar">
                        <input  name="file" id='upload_img'  type="file">
                        <input type="hidden" name="avtar" id='avtar'>
                    </td>
                    <td class="vatop tips">请上传后缀名为：*.jpeg *.jpg *.png 的文件</td>
                </tr>
                <tr class="noborder">
                    <td class="required w120">{$Think.lang.fuwu_personal_sex}:</td>
                    <td class="vatop rowform">
                        <input type="radio" value="0" name="sex" {if $data.sex == 0}checked {/if}>{$Think.lang.fuwu_personal_sex0}&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" value="1" name="sex" {if $data.sex == 1}checked {/if}>{$Think.lang.fuwu_personal_sex1}&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" value="2" name="sex" {if $data.sex == 2}checked {/if}>{$Think.lang.fuwu_personal_sex2}&nbsp;&nbsp;&nbsp;&nbsp;
                    </td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120">{$Think.lang.fuwu_personal_birthday}:</td>
                    <td class="vatop rowform">
                        <input class="txt date" type="text" value="{$data.birthday}" id="birthday" name="birthday">

                    </td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120">{$Think.lang.fuwu_personal_address}:</td>
                    <td class="vatop">
                        <input type="hidden" name="address" id="address" value="{$data.address}"/>
                    </td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120">{$Think.lang.fuwu_personal_kouhao}:</td>
                    <td class="vatop rowform">
                        <textarea name="kouhao" id="kouhao" class="txt">{$data.kouhao}
                        </textarea>
                    </td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120">{$Think.lang.fuwu_personal_week}:</td>
                    <td class="vatop rowform" style="width: 450px; ">
                        <select name="startweek" id="startweek">
                            <option value="">--请选择</option>
                            {foreach name='weekArr' item='v' key='k'}
                            <option value="{$k}" {if $data.startweek == $k} selected{/if}>{$v}</option>
                            {/foreach}
                        </select>
                        <span>至</span>
                        <select name="endweek" id="endweek"  style="margin-left:10px; ">
                            <option>--请选择</option>
                            {foreach name='weekArr' item='v'  key='k'}
                            <option value="{$k}"  {if $data.endweek == $k} selected{/if}>{$v}</option>
                            {/foreach}
                        </select>
                        <br/>
                        <select name="starttime" id="starttime" style="margin-top: 10px;">
                            <option>--请选择</option>
                            {foreach name='timeArr' item='v'}
                            <option  value="{$v}" {if $data.starttime == $v} selected{/if}>{$v}</option>
                            {/foreach}
                        </select>
                        <span>至</span>
                        <select name="endtime" id="endtime"  style="margin-left:10px; ">
                            <option>--请选择</option>
                            {foreach name='timeArr' item='v'}
                            <option   value="{$v}" {if $data.endtime == $v} selected{/if}>{$v}</option>
                            {/foreach}
                        </select>
                    </td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120">{$Think.lang.fuwu_personal_gradeid}:</td>
                    <td class="vatop rowform">
                        <select name="gradeid" id="gradeid">
                            {foreach name='gradeArr' item='v'}
                            <option value="{$v.id}"  {if $data.gradeid== $v.id} selected {/if}>{$v.name}</option>
                            {/foreach}
                        </select>
                    </td>
                    <td class="vatop tips"></td>
                </tr>

                <tr class="noborder">
                    <td class="required w120"><label>{$Think.lang.fuwu_personal_status}: </label></td>
                    <td class="vatop rowform onoff">
                        <label for="status1" class="cb-enable {if $data.status == '1'}selected{/if}" title="{$Think.lang.fuwu_personal_status1}"><span>{$Think.lang.fuwu_personal_status1}</span></label>
                        <label for="status0" class="cb-disable {if $data.status == '0'}selected{/if}" title="{$Think.lang.fuwu_personal_status0}"><span>{$Think.lang.fuwu_personal_status0}</span></label>
                        <input id="status1" name="status" {if $data.status == '1'}checked="checked"{/if} value="1" type="radio">
                        <input id="status0" name="status" {if $data.status == '0'}checked="checked"{/if} value="0" type="radio">
                    </td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120"><label>{$Think.lang.fuwu_personal_admin_name}: </label></td>
                    <td class="vatop rowform"><input type="text" value="{$data.admin_name}" name="admin_name" id="admin_name" class="txt" readonly="readonly"></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120"><label>{$Think.lang.fuwu_personal_createdtime}: </label></td>
                    <td class="vatop rowform"><input type="text" value="{$data.created_at}" name="created_at" id="created_at" class="txt" readonly="readonly" ></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder">
                    <td class="required w120"><label>{$Think.lang.fuwu_personal_updatedtime}: </label></td>
                    <td class="vatop rowform"><input type="text" value="{$data.updated_at}" name="updated_at" id="updated_at" class="txt" readonly="readonly" ></td>
                    <td class="vatop tips"></td>
                </tr>
                </tbody>
                <tfoot>
                <tr class="tfoot">
                    <td colspan="15" ><input class="btn" type="submit" style="line-height: 30px;" value="{$Think.lang.ds_submit}"/></td>
                </tr>
                </tfoot>
            </table>
        </form>
    </div>
<script src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js"></script>
<link rel="stylesheet" href="{$Think.CHAT_SITE_URL}/css/chat.css">
<script>
    $(function () {
        $("#address").ds_region();
        $('#birthday').datepicker({dateFormat: 'yy-mm-dd',birthday: '{$data.birthday}'});
    })
//按钮先执行验证再提交表
    $(document).ready(function () {
        $("#form").validate({
        errorPlacement: function (error,element) {
                error.appendTo(element.parent().parent().find('td:last'));
            },
            rules:{
                skillid:{
                  required:true
                },
                phone:{
                    required:true,
                    checkphone:true,
                    remote:{
                        url: ADMINSITEURL+'/Fupersonal/ajax.html?branch=check_phone',
                        type:'get',
                        data:{
                            phone:function () {
                                return $('#phone').val();
                            },
                            id:function () {
                                return $('#id').val();
                            }
                        }
                    }
                },
                password:{
                    required:true,
                    minlength:6
                },
                quren_password:{
                    required:true,
                    equalTo:"#password"
                },
                startweek:{
                    remote:{
                        url: ADMINSITEURL+'/Fupersonal/ajax.html?branch=check_week',
                        type:'get',
                        data:{
                            startweek:function () {
                                return $('#startweek').val();
                            },
                            endweek:function () {
                                return $('#endweek').val();
                            }
                        }
                    }
                },
                starttime:{
                    remote:{
                        url: ADMINSITEURL+'/Fupersonal/ajax.html?branch=check_time',
                        type:'get',
                        data:{
                            starttime:function () {
                                return $('#starttime').val();
                            },
                            endtime:function () {
                                return $('#endtime').val();
                            }
                        }
                    }
                }


            },
            messages:{
                skillid:{
                    required:'{$Think.lang.fuwu_personal_skillid_bi}',
                },
                phone:{
                    required:'{$Think.lang.fuwu_personal_phone_bi}',
                    remote:'{$Think.lang.fuwu_personal_phone_unique}',

                },
                password:{
                    required:'{$Think.lang.fuwu_personal_password_bi}',
                    minlength:'{$Think.lang.fuwu_personal_password_min}',
                },
                quren_password:{
                    required:'{$Think.lang.fuwu_personal_quren_password_bi}',
                    equalTo:'{$Think.lang.fuwu_personal_quren_password_tong}',
                },
                startweek:{
                    remote:'工作天数错误'
                },
                starttime:{
                    remote:'时间错误'
                }

            }
        });
        //自定义正则表达示验证方法
        $.validator.addMethod("checkphone",function(value,element,params){
            var checkQQ = /^[1][3,4,5,7,8,9][0-9]{9}$/;
            return this.optional(element)||(checkQQ.test(value));
        },"{$Think.lang.fuwu_personal_phone_geshi}");
    });
$(document).on('change','#upload_img',function() {
    var files = document.getElementById('upload_img').files[0];
    var formData = new FormData();
    formData.append('file',files);
    layer.msg('正在上传，请稍后');
    $.ajax({
        //请求方式
        type : "POST",
        //请求地址
        url : "ajax_upload",
        data : formData,
        cache:false,  //默认是true，但是一般不做缓存
        processData:false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
        contentType:false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
        //请求成功
        success : function(result) {
            if(result.err==0){
                layer.msg(result.msg);
                $('#avtar').val(result.data);
               if ($("#upload_img_avtar_2").length >0){
                   $("#upload_img_avtar_2").remove();
               }
                $('#upload_img_avtar').prepend('<img src="'+result.data+'" width="100px" id="upload_img_avtar_2"/>')
            }else{
                $('#avtar').val('');
                alert('文件信息错误,请重新上传');return false;
            }



        },
        //请求失败，包含具体的错误信息
        error : function(e){
            console.log(e.status);
            console.log(e.responseText);
        }
    });

});
</script>